home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / IconUtilCheck / Source / IconUtilCheck.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.2 KB  |  85 lines  |  [TEXT/CWIE]

  1. /****
  2.     According to the Tech Note OV - 16, "Inside Macintosh: More Macintosh 
  3.     Toolbox, page 5-7, specifies that the gestaltIconUtilitiesAttr - 'icon'
  4.     gestalt selector can be used to determine whether the icon utilities
  5.     are present under System 7.x.   Note that this selector is included in
  6.     the GestaltEqu files.  It turns out that this selector is not
  7.     implemented until System Software v7.1.2.  To check for the existence of
  8.     these utilities, use the TrapAvailable code to check for the 
  9.     _IconDispatch, (0xABC9) trap.  The TrapAvailable code is presented in
  10.     Inside Macintosh VI 3-8, and as sample code in many of the snippets
  11.     on the Developer CD."
  12.  
  13.     This snippet shows how to determine whether the Icon Utilities
  14.     are available.
  15.         
  16.     Written by Virginia (Ginny) McCulloh
  17.     Apple Developer Technical Support
  18.     August 1995, Cupertino, CA
  19.     Copyright 1995, Apple Computer, Inc.
  20.  
  21.     This runs under Think C 7.0.4, CodeWarrior 6,
  22.      and MPW 3.3.1 with the Universal Headers.
  23. ****/
  24.  
  25. //updates 8/96: Prefix.h added as prefix file for 68K and PPC MC projects;
  26. //old routine names changed
  27.  
  28. #include <stdio.h>
  29. #include <Types.h>
  30. #include <OSUtils.h>
  31. #include <GestaltEqu.h>
  32.  
  33. #ifndef __TRAPS__
  34. #include <Traps.h>
  35. #endif
  36.  
  37. #define    TrapMask        0x0800
  38.  
  39.  
  40. Boolean TrapAvailable(short theTrap);
  41. short NumToolboxTraps(void);
  42. TrapType GetTrapType(short theTrap);
  43.     
  44. short NumToolboxTraps(void)
  45. {
  46.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E,ToolTrap))
  47.         return 0x0200;
  48.     else
  49.         return 0x0400;
  50. }
  51.  
  52. TrapType GetTrapType(short theTrap)
  53. {
  54.     if ((theTrap & TrapMask) > 0)
  55.         return ToolTrap;
  56.     else
  57.         return OSTrap;
  58. }
  59.  
  60. Boolean TrapAvailable(short theTrap)
  61. {
  62.     TrapType tType;
  63.     Boolean isAvail;
  64.     
  65.     tType = GetTrapType(theTrap);
  66.     if (tType == ToolTrap)
  67.         {
  68.             theTrap &= 0x07FF;
  69.             if (theTrap >= NumToolboxTraps())
  70.                 theTrap = _Unimplemented;
  71.         }
  72.     
  73.     isAvail = NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap);
  74.     return isAvail;
  75. }
  76.  
  77. void main(void)
  78. {
  79.     printf("Testing for presence of Icon Utilities\n");
  80.     if (TrapAvailable(_IconDispatch))
  81.         printf("Icon Utilities are available\n");
  82.     else
  83.         printf("Icon Utilities are not available\n");
  84. }
  85.